package com.boc.langxiang.ui.adapter.me;

import android.content.Context;
import android.util.Log;
import android.widget.ImageView;

import com.boc.langxiang.R;
import com.boc.langxiang.contract.me.MyExerciseWantFragmentContract;
import com.boc.langxiang.entity.response.TobecanyuContentBean;
import com.boc.langxiang.manager.PicassoImageLoader;
import com.boc.langxiang.util.StringUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jakewharton.rxbinding.view.RxView;

import java.util.List;
import java.util.concurrent.TimeUnit;

import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;

public class MyExerciseWantFragmentRVAdapter extends BaseQuickAdapter<TobecanyuContentBean> {

    private boolean mVisible;
    private MyExerciseWantFragmentContract.View mView;

    public MyExerciseWantFragmentRVAdapter(Context context, List<TobecanyuContentBean> data, MyExerciseWantFragmentContract.View view) {
        super(R.layout.item_me_myexercise_want, data);
        this.mView = view;
    }

    @Override
    protected void convert(final BaseViewHolder helper, final TobecanyuContentBean item) {
        helper.setVisible(R.id.fralayout_me_orders_exercises, mVisible)
                .setText(R.id.tv_me_myexercise_wantnum, "想参与\t" + item.getCount_be_canyu())
                .setText(R.id.tv_me_myexercise_joinnum, "参与\t" + item.getCount_canyu())
                .setText(R.id.tv_me_myexercise_title, StringUtil.isEmpty(item.getTitle()) ? "" : item.getTitle());
               /* .setOnClickListener(R.id.iv_me_myexercise_delete, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mView.onDeleteIconClick(helper.getAdapterPosition());
                    }
                });*/

        PicassoImageLoader.getInstance().displayUrlImage(mContext, item.getPhotourl()
                , (ImageView) helper.getView(R.id.img_iv));

        RxView.clicks(((ImageView) helper.getView(R.id.iv_me_myexercise_delete)))
                .throttleFirst(5000, TimeUnit.MILLISECONDS)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        Log.d("RVAdapter", "MyExerciseWantFragment click ");
                        mView.onDeleteIconClick(helper.getAdapterPosition(), item.getId());
                    }
                });
    }

    public void setDeleteIconVisiblity(boolean visible) {
        this.mVisible = visible;
        notifyDataSetChanged();
    }
}
